package cn.ydt.ydt.community.webapi.service.impl;

import cn.ydt.ydt.community.service.INucleicAcidTestAppointService;
import cn.ydt.ydt.community.webapi.mapper.NucleicAcidTestAppointmentMapper;
import cn.ydt.ydt.community.webapi.utils.SecurityContextUtils;
import cn.ydt.ydt.pojo.community.dto.NucleicAcidTestAppointmentDTO;
import cn.ydt.ydt.pojo.community.vo.SelectNucleicTestResultVO;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;


@Service
@EnableKnife4j
@Slf4j
public class NucleicAcidTestAppointmentServiceImpl implements INucleicAcidTestAppointService {

    @Autowired
    NucleicAcidTestAppointmentMapper nucleicAcidTestAppointmentMapper;

    @Override
    public void appointment(NucleicAcidTestAppointmentDTO nucleicAcidTestAppointDTO) {
        LocalDateTime localDateTime = LocalDateTime.now();
        Date date = Date.from( localDateTime.atZone( ZoneId.systemDefault()).toInstant());
        NucleicAcidTestAppointmentDTO nucleicAcidTestAppointmentDTO1 = new NucleicAcidTestAppointmentDTO();
        BeanUtils.copyProperties(nucleicAcidTestAppointDTO,nucleicAcidTestAppointmentDTO1);
        nucleicAcidTestAppointmentDTO1.setNucleicAcidTestAppointmentTime(date);
        Long userId = SecurityContextUtils.getUserId();
        Long communityId = SecurityContextUtils.getUserInfo().getCommunityId();
        nucleicAcidTestAppointDTO.setCommunityId(communityId);
        nucleicAcidTestAppointDTO.setUserId(userId);
        nucleicAcidTestAppointmentMapper.insertNucleicAcidTestAppointment(nucleicAcidTestAppointmentDTO1);
    }

    @Override
    public List<SelectNucleicTestResultVO> selectResult() {
        Long user = SecurityContextUtils.getUserId();
        return nucleicAcidTestAppointmentMapper.selectNucleicResult(user);
    }

    @Override
    public List<SelectNucleicTestResultVO> selectAllResult() {
        Long user = SecurityContextUtils.getNetCommunityId();
        return nucleicAcidTestAppointmentMapper.selectAllNucleicResult(user);
    }

}
